/*
 * Copyright (c) 2021 huipei.x
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.xphsc.web.log.context;

import cn.xphsc.web.utils.Collects;
import org.springframework.context.expression.MethodBasedEvaluationContext;
import org.springframework.core.ParameterNameDiscoverer;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * {@link }
 * @author <a href="xiongpeih@163.com">huipei.x</a>
 * @description:
 * @since 1.0.0
 */
public class OperationLogEvaluationContext extends MethodBasedEvaluationContext {

    public OperationLogEvaluationContext(Object rootObject, Method method, Object[] arguments,
                                         ParameterNameDiscoverer parameterNameDiscoverer,
                                         Object retObj, String errorMsg, Map<String, Object> operationLogContext) {
        super(rootObject, method, arguments, parameterNameDiscoverer);
        setVariable("_retObj", retObj);
        setVariable("_errorMsg", errorMsg);
        if(Collects.isNotEmpty(operationLogContext)){
            for(Map.Entry<String,Object> entity:operationLogContext.entrySet()){
                    setVariable(entity.getKey(),entity.getValue());
            }
        }
        setVariable("_context", operationLogContext);
    }
}
